package com.leo.erp.web.accounthead;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.leo.erp.dto.AccountHeadExecution;
import com.leo.erp.service.AccountHeadService;
import com.leo.erp.util.GlobalRuntimeException;
import com.leo.erp.util.HttpServletRequestUtil;

@Controller
@RequestMapping(value = "/accountHead")
public class AccountHeadManagementController {
	@Autowired
	private AccountHeadService accountHeadService;
	
	/**
	 * 查询单位的累计应收和累计应付，收预付款不计入此处
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/findTotalPay")
	@ResponseBody
	public Map<String, Object> findTotalPay(HttpServletRequest request){
		Map<String, Object> modelMap = new HashMap<>();
		//获取前台传过来的值
		int supplierId = HttpServletRequestUtil.getInt(request, "supplierId");
		String endTime = HttpServletRequestUtil.getString(request, "endTime");
		String supType = HttpServletRequestUtil.getString(request, "supType");
		try {
			AccountHeadExecution ae = accountHeadService.findTotalPay(supplierId, endTime, supType);
			modelMap.put("success", true);
			modelMap.put("getAllMoney", ae.getTotalPay());
		} catch (GlobalRuntimeException e) {
			e.printStackTrace();
			modelMap.put("success", false);
			modelMap.put("msg", "获取数据失败");
		}
		return modelMap;
	}
}
